use std::env;

use solan::transfer_sol;

fn main() {
    let rpc_url = env::var("RPC_URL").unwrap_or_else(|_| "https://api.devnet.solana.com".to_string());
    let secret = match env::var("SECRET") {
        Ok(v) => v,
        Err(_) => {
            eprintln!("缺少 SECRET 环境变量（支持 0x 十六进制 / JSON 数组 / Base58）。示例：\n set SECRET=0x<128hex 或 64hex> 或 set SECRET=[12,34,...,32或64字节] 或 set SECRET=<base58>");
            return;
        }
    };
    let to = match env::var("TO") {
        Ok(v) => v,
        Err(_) => {
            eprintln!("缺少 TO 环境变量（目标地址 Base58 或 0x 十六进制）。示例：\n set TO=<recipient_base58> 或 set TO=0x<64hex>");
            return;
        }
    };
    let amount_sol: f64 = match env::var("AMOUNT_SOL") {
        Ok(v) => v.parse().unwrap_or(0.001),
        Err(_) => 0.001,
    };

    match transfer_sol(&rpc_url, &secret, &to, amount_sol) {
        Ok(sig) => println!("交易成功，签名: {}", sig),
        Err(e) => eprintln!("交易失败: {}", e),
    }
}